﻿#include "TableCheckBox.h"

#include <QVBoxLayout>

TableCheckBox::TableCheckBox(QWidget *parent)
    : QWidget(parent)
    , m_cb(new QCheckBox(this))
{
    // CheckBox居中对齐
    QVBoxLayout* vbl = new QVBoxLayout(this);
    vbl->setMargin(0);

    vbl->addWidget(m_cb, 0, Qt::AlignCenter);

    setLayout(vbl);
    vbl->setMargin(0);

    connect(m_cb, &QCheckBox::stateChanged, this, &TableCheckBox::stateChanged);
    m_cb->setText("");
    m_cb->setStyleSheet(
        "QCheckBox {"
        "    spacing: 0px;"        /* indicator 与文字间距 */
        "    padding: 0px;"        /* 清除所有 padding */
        "    margin: 0px;"         /* 清除 margin */
        "}");
}

void TableCheckBox::setChecked(bool ck)
{
    m_cb->setChecked(ck);
}

bool TableCheckBox::isChecked() const
{
    return m_cb->isChecked();
}
